function smallestNumber(arr) {
    function compr(a, b) {
        let x = Number(`${a}${b}`)
        let y = Number(`${b}${a}`)
        return x - y
    }
    return arr.sort(compr)
}

let nums = [3, 30, 34, 5, 9]
console.log(smallestNumber(nums));